import { defineStore } from "pinia";
import * as questionApi from "@/api/train/question";
import { Question, QuestionActionRecordWithId, ToggleFavoriteQuestionParams, UpdateActionRecordParams } from "@/types/practice";

export const usePracticeStore = defineStore("practice", {
  persist: {
    paths: ["indexHistory", "lastPullActionRecordTime", "lastPushActionRecordTime"],
  },

  state: () => ({
    actionRecordMap: new Map<Question["id"], QuestionActionRecordWithId>(),
    indexHistory: {} as { [key: string]: number },
    lastPullActionRecordTime: 0,
    lastPushActionRecordTime: 0,
  }),

  actions: {
    // 更新历史下标
    updateIndexHistory(uniqueFlag: string, index: number) {
      this.indexHistory[uniqueFlag] = index;
    },
  },
});
